package com.luzhikun.path.com.luzhikun.myExamSystem.controller; /**
 * ClassName: ${NAME}
 * Description: ${Description}
 * date: 2021/4/22 21:33
 *
 * @author luzhikun
 * @version
 * @since JDK 1.8
 */

import com.luzhikun.path.com.luzhikun.myExamSystem.dao.UserDao;
import com.luzhikun.path.com.luzhikun.myExamSystem.model.User;

import javax.servlet.*;
import javax.servlet.http.*;
import java.io.IOException;
import java.io.PrintWriter;
import java.util.List;

public class UserFindServlet extends HttpServlet {
    @Override
    protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {

        //创建用户窗口对象
        UserDao userDao = new UserDao();
        //创建输出流
        PrintWriter out = null;
        //1.调用Dao将查询命令推送到数据库服务器上，得到所有的用户信息，【list】
        List<User> users = userDao.getUsers();
        //2.[调用响应对象]将用户信息，结合table标签命令以二进制的形式写入到响应体中
        //设置字符编码
        response.setContentType("text/html;charset=UTF-8");
        //画表格
        out = response.getWriter();
        out.print("<table border='2' align='center'>");

        out.print("<tr>");
        out.print("<td> 用户id </td>");
        out.print("<td> 用户姓名 </td>");
        out.print("<td> 用户密码 </td>");
        out.print("<td> 用户性别 </td>");
        out.print("<td> 用户邮箱 </td>");
        out.print("<td> 操作 </td>");
        out.print("</tr>");
        for (User user : users) {
            out.print("<tr>");
            out.print("<td>" + user.getUserId() + "</td>");
            out.print("<td>" + user.getUserName() + " </td>");
            out.print("<td>" + user.getPassword() + "</td>");
            out.print("<td>" + user.getSex() + "</td>");
            out.print("<td>" + user.getEmail() + "</td>");
            out.print("<td><a href='/myWeb/user/delete?userid=" + user.getUserId() + "'>删除用户</a></td>");
            out.print("</tr>");
        }

        out.print("</table>");


    }

}
